import openpyxl
class ExcelUtil:

    @staticmethod
    def get_data(file_name, sheet_name):
        workbook=openpyxl.load_workbook(file_name)
        worksheet=workbook[sheet_name]
        return [[worksheet.cell(row=i,column=j).value for j in range(1,worksheet.max_column+1)] for i in range(2,worksheet.max_row+1)]
    @staticmethod
    def write_head(file_name,sheet_name,head):
    #     在第一行中写入数据
        workbook=openpyxl.load_workbook(file_name)
        worksheet=workbook[sheet_name]
        for i in range(len(head)):
            worksheet.cell(row=1,column=i+1).value=head[i]
        workbook.save(file_name)
    @staticmethod
    def write_data(file_name,sheet_name,data):
        workbook=openpyxl.load_workbook(file_name)
        worksheet=workbook[sheet_name]
        for i in range(len(data)):
            for j in range(len(data[i])):
                worksheet.cell(row=i+2,column=j+1).value=data[i][j]
        workbook.save(file_name)
